package util

import (
	"errors"
	"github.com/go-resty/resty/v2"
)

func Get(url string, result ...any) (*resty.Response, error) {
	if url == "" {
		return nil, errors.New("请求地址不能为空")
	}

	req := resty.New().R()

	if result != nil {
		req.SetResult(result)
	}

	return req.Get(url)
}

func Post(url string, body any, result ...any) (*resty.Response, error) {
	if url == "" {
		return nil, errors.New("请求地址不能为空")
	}

	req := resty.New().R()

	if body != nil {
		req.SetBody(body)
	}

	if result != nil {
		req.SetResult(result)
	}

	return req.Post(url)
}
